(function() {

	require(['jquery', 'Magnifier', 'jbox', __uri('./app.js')], function($) {

		$(function() {

			$('.goods .inner>.bottom').css({minHeight: $('.goods .inner .left .inside').height()})

			$(".preview .big-img img").imagezoom({xzoom: 390, yzoom: 390});

			$('.preview .small-img ul li img').on('mousemove', function() {
				$(".preview .big-img img").attr("src",$(this).attr("src"));
				$(".preview .big-img img").attr("rel",$(this).attr("rel"));
				 $(this).parents("li").addClass("on").siblings().removeClass("on");
			});

			$('.tabs .tab').on('click', function() {//tab切换

				$(this).addClass('active').siblings('.tabs .tab').removeClass('active');
				$('.tab-block').eq($(this).index()).show().siblings('.tab-block').hide();
				$('html, body').animate({scrollTop: 1000}, 300);
			});

			$('.total-price .my-cart').on('click', function() {//采购详情淡入淡出

				$('.total-price .detail').fadeToggle('fast');
			});

			$('html, body').on('click', function(e) {

				if(e.target.className != 'act' && $(e.target).parents('.total-price .detail').length == 0 && e.target != $('.total-price .my-cart')[0])
					$('.total-price .detail').fadeOut('fast');
			});

			$('.goods .bottom .tabs p.price').on('click', function() {
				$('html, body').animate({scrollTop: 0});
			});

			$('.sku-list.size span.tar').click(function() {

				$('.sku-list.size .list').toggleClass('on');
				sizeShow();
			});

			$('.sku-list.size i.add, .sku-list.size i.sub').click(function() {

				if($('.sku-list.size .list').height()==$('.sku-list.size .list')[0].scrollHeight) return false;
				$('.sku-list.size .list').addClass('on');
				sizeShow();
			});

			function sizeShow() {//size更多

				if(!$('.sku-list.size .list').hasClass('on')) {
					$('.sku-list.size .list').animate({height: 119,maxHeight: 119}, 250);
					$('.sku-list.size span.tar').html('更多');
				}
				else {
					$('.sku-list.size .list').animate({height: $('.sku-list.size .list')[0].scrollHeight,maxHeight: $('.sku-list.size .list')[0].scrollHeight}, 250);
					$('.sku-list.size span.tar').html('收起');
				}
			}

			var start = $('.goods .bottom .tabs').offset().top;
			$(window).on('scroll', scroll);

			function scroll(e) {
				
				var scrollTop = $(window).scrollTop();
				var left = $('.goods .inner .left .inside');
				var tabs = $('.goods .bottom .tabs');
				
				var bottom = $('.goods .inner>.bottom');
				var bottomH = bottom.offset().top + bottom.height() - scrollTop;
				var st = bottom.scrollTop() + bottom.height();

				if(scrollTop >= start) {

					bottom.children('.right').css({
						paddingTop: 40
					});

					left.css({
						visibility: 'visible',
						position: 'fixed',
						top: 0,
						left: left.offset().left,
						zIndex: 10
					}).addClass('scroll');

					tabs.css({
						visibility: 'visible',
						position: 'fixed',
						top: 0,
						left: tabs.offset().left,
						zIndex: 10
					}).addClass('scroll');

					if(bottomH <= left.height()) {
						left.css({
							 top: bottomH - left.height()
						});
						if(bottomH < 100){
							tabs.css({visibility: 'hidden'});
						}
					}  else {
						left.css({
							 top: 0
						});
					}
				} else {

					bottom.children('.right').removeAttr('style');
					left.removeAttr('style').removeClass('scroll');
					tabs.removeAttr('style').removeClass('scroll');
				}
			}

			window._bd_share_config={
				"common":{
					"bdSnsKey":{},
					"bdText":"华履云商",
					"bdMini":"2",
					"bdMiniList":false,
					"bdPic":"",
					"bdStyle":"1",
					"bdSize":"16"
				},"share":{}};

			new jBox('Tooltip', {
				title: '<div class="bdsharebuttonbox">\
							<a class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>\
							<a class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>\
							<a class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>\
							<a class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>\
							<a class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>\
							<a class="bds_more" data-cmd="more">分享到：</a>\
						</div>',
				closeOnMouseleave: true,
				attach: $('.info .share'),
				zIndex: 10,
				// pointer: false,
				position: {
					x: $('.info .share').offset().left - 170,
					y: 'bottom'
				},	
				onCreated: function() {
					var _this = this.target;
					
					if(!this.target.hasClass('on')) {
						window._bd_share_config={
							"common":{
								"bdSnsKey":{},
								"bdText": $('.right.float-r > .title').html() + '[华履云商]',
								"bdMini":"2",
								"bdMiniList":false,
								"bdPic":"",
								"bdStyle":"1",
								"bdSize":"16"
							},
							"share":{}
						};
						require(['http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)], function() {
							_this.addClass('on');
						});
					}
				}
			});
		});
	});
})();